package com.study.ctripapollo.controller;

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import com.study.ctripapollo.service.ApolloService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author flwu
 * @date 2020/3/16 3:54 PM
 * @MOTTO 保持空和敬畏
 */
@RestController
public class HelloController {

    private static Logger logger = LoggerFactory.getLogger(HelloController.class);

    @Autowired
    private ApolloService apolloService;

    @RequestMapping(value = "/{key}")
    public String getPort(@PathVariable("key") String key) {
        return ConfigService.getAppConfig().getProperty(key, "undefined");
    }

    @RequestMapping(value = "/key/name")
    public String getKey() {
        return apolloService.getKey();
    }

    @RequestMapping(value = "/key/api/{name}")
    public String getKeyByCom(@PathVariable("name") String name) {
        return apolloService.getName(name);
    }

    @RequestMapping(value="/ns/{name}")
    public String getNameSpace(@PathVariable("name") String name) {
        return ConfigService.getConfig("TEST1.lubai.home").getProperty(name, "no exist");
    }
}
